<!doctype html>
<html class="no-js" lang="en">
<!--<![endif]-->
<head>
<meta name="layout" content="common">
<title>Manage Voucher</title>

<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.8.2/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="${resource(dir:'css', file:'demo_table.css') }">
<!-- DataTables -->
<!-- script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.8.2/jquery.dataTables.min.js"></script-->
<script type="text/javascript" charset="utf8" src="${resource(dir:'js', file:'jquery.dataTables.min.js') }"></script>
</head>
<body id="body">
	<h2>Manage Voucher</h2>
	<hr />

	<g:if test="${flash.message}">
		<div class="alert alert-success">
			<img src="${resource(dir:'images', file:'icon_successful.png') }" />&nbsp;&nbsp;${flash.message}
		</div>
	</g:if>
	<div class="row>">
		<g:form name="voucherList" method="POST" action="list">
		<table width="100%">
			<tr>
				<td width="25%">Title</td>
				<td>
					<g:textField name="searchTitle" value="${searchTitle}" maxLength="100" style="width:220px;"/>
				</td>
			</tr>
			<tr>
				<td>Country</td>
				<td>
					<g:select name="searchCountry" from="${com.mastercard.labs.Country.list(sort: "name", order: "asc")}" optionKey="id" optionValue="name" value="${searchCountry}" noSelection="${['':'Select One...']}"/>
				</td>
			</tr>
			<tr>
				<td>Merchant</td>
				<td>
					<g:select name="searchMerchant" from="${com.mastercard.labs.Merchant.list(sort: "name", order: "asc")}" optionKey="id" optionValue="name" value="${searchMerchant}" noSelection="${['':'Select One...']}"/>
				</td>
			</tr>
			<tr>
				<td>Categories</td>
				<td>
					<g:select name="searchCategories" from="${com.mastercard.labs.Category.list(sort: "name", order: "asc")}" optionKey="id" optionValue="name" value="${searchCategories}" noSelection="${['':'Select One...']}"/>
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<g:submitButton name="search" value="Search" class="btn btn-primary" />
					<g:actionSubmit action="create" value="Create New Voucher" class="btn" />
				</td>
			</tr>
		</table>
		<br/><br/>
		<g:if test="${params.search=="Search"}">
		<table cellpadding="0" cellspacing="0" border="0" class="display" width="95%" id="userList">
			<thead>
				<tr>
					<td width="5%"><b>SN</b></td>
					<td><b>Title</b></td> 
					<td width="20%"><b>Category</b></td>
					<td width="10%"><b>Start Date</b></td>
					<td width="10%"><b>End Date</b></td>
					<td width="10%"><b>rdptPoint</b></td>
					<td width="8%"><b>Image</b></td>
					<td width="10%"><b>Total Quantity</b></td>
				</tr>
			</thead>
			<tbody>
				<g:each in="${voucherInstanceList}" var="usr" status="usrStat">
					<tr class="gradeA" id="transaction-row-${usr.title }">
						<td>${usrStat + 1}</td>
						<td><g:link action="edit" id="${usr.id}" params="[searchTitle: searchTitle, searchMerchant: searchMerchant, searchCategories: searchCategories]">${fieldValue(bean: usr, field: "title")}</g:link></td>
						<td>${usr.categories?.name}</td>
						<td><g:formatDate date="${usr.startDate}"  format="dd/MM/yyyy" /></td>
						<td><g:formatDate date="${usr.endDate}"  format="dd/MM/yyyy" /></td>
						<td>${fieldValue(bean: usr, field: "rdptPoint")}</td>
						<td><g:img uri="${fieldValue(bean: usr, field: "imageUrl")}" height="30" width="30" /></td>
						<td>${fieldValue(bean: usr, field: "totalQuantity")}</td>
					</tr>
				</g:each>
			</tbody>
		</table>
		</g:if>
		</g:form>
	</div>
	<br/>
	<script src="${resource(dir:'js/app', file:'user_search.js') }"></script>
</body>
</html>